package org.testis.gui.mvc.model.testdesign;

import org.testis.gui.mvc.model.*;
import org.testis.gui.mvc.controller.testdesign.SelectController;
import org.testis.utils.tree.MyDefaultMutableTreeNode;
import java.util.LinkedList;


/**
 *
 * @author Cahit Emir Erel
 */
public class SelectModel extends AbstractModel
{

    private Boolean m_selecterVisibility = false;
    private LinkedList<MyDefaultMutableTreeNode> m_selectedList =
        new LinkedList<MyDefaultMutableTreeNode>();
    private MyDefaultMutableTreeNode m_selectedNode = null;
    private MyDefaultMutableTreeNode m_root = null;
    private String m_title = "";
    private String m_properties = "";


    /**
     * Default constructor
     */
    public SelectModel()
    {

    }

    public void setProperties(String properties) {
        String oldProperties = m_properties;
        m_properties = properties;
        firePropertyChange(SelectController.PROPERTIES,
                           oldProperties,
                           properties);
    }

    public void setSelectedNumber(String selectedNo) {
        firePropertyChange(SelectController.CHANGE_SELECTED_NO,
                           null,
                           selectedNo);
    }

    public String getProperties() {
        return m_properties;
    }


    public void setRefreshTree(Boolean refresh)
    {
        if (refresh != null && refresh) {
            firePropertyChange(SelectController.TREE_REFRESH,
                               false,
                               true);
        }
    }


    public void setRoot(MyDefaultMutableTreeNode root)
    {
        MyDefaultMutableTreeNode oldRoot = m_root;
        m_root = root;
        firePropertyChange(SelectController.TREE_REFRESH,
                           oldRoot,
                           root);
    }


    public MyDefaultMutableTreeNode getRoot()
    {
        return m_root;
    }


    public void setTitle(String title)
    {
        if (title == null) {
            title = "";
        }
        String oldTitle = m_title;
        m_title = title;
        firePropertyChange(SelectController.CHANGE_TITLE,
                           oldTitle,
                           title);
    }


    public String getTitle()
    {
        return m_title;
    }


    public void setLoadTree(MyDefaultMutableTreeNode tree)
    {
        if (tree == null) {
            return;
        }
        m_selectedList.add(tree);
        firePropertyChange(SelectController.TREE_LOAD,
                           null,
                           tree);
    }

    
    public MyDefaultMutableTreeNode[] getLoadTree()
    {
        return m_selectedList.toArray(new MyDefaultMutableTreeNode[m_selectedList.size()]);
    }


    public MyDefaultMutableTreeNode getSelectedNode()
    {
        return m_selectedNode;
    }


    public void setSelectedNode(MyDefaultMutableTreeNode selectedNode)
    {
        MyDefaultMutableTreeNode oldSelectedNode = m_selectedNode;
        m_selectedNode = selectedNode;
        firePropertyChange(SelectController.SELECT_DESIGN_PART,
                           oldSelectedNode,
                           selectedNode);
    }


    public void setShowSelecter(Boolean selecterVisibility)
    {
        if (selecterVisibility == null) {
            return;
        }
        Boolean oldSelecterVisibility = m_selecterVisibility;
        m_selecterVisibility = selecterVisibility;
        firePropertyChange(SelectController.SHOW_SELECTER,
                           oldSelecterVisibility,
                           selecterVisibility);
    }


    public Boolean getShowSelecter()
    {
        return m_selecterVisibility;
    }

    public void setExpandPath(MyDefaultMutableTreeNode node) {
        if (node == null) {
            return;
        }
        firePropertyChange(SelectController.EXPAND_PATH,
                           null,
                           node);
    }
}
